import { EventEmitter } from "./dist";
// import EventEmitter from "events";

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
// 只做一次，这样我们就不会永远循环
myEmitter.once('newListener', (event: string, listener: any) => {
  if (event === 'myEvent') {
    myEmitter.on('myEvent', () => {
      console.log('B');
    });
  }
});

// 第二个监听器函数 订阅event事件
myEmitter.on('myEvent', (...params:any[]) => {
  console.log('A');
});

// 触发 event 事件
myEmitter.emit('myEvent','other params');
// Prints:
//   B
//   A
console.log(myEmitter.listenerCount('myEvent'));
console.log(myEmitter.listeners('myEvent'));

